package 模拟;

public class 提莫攻击2 {
    //https://leetcode.cn/problems/teemo-attacking/description/
    public int findPoisonedDuration1(int[] timeSeries, int duration) {
        if(timeSeries.length == 1) return duration;
        int ret = 0;
        for(int left = 0, right = 1; right < timeSeries.length;left++,right++) {
            int gap = timeSeries[right] - timeSeries[left];
            if(gap < duration) ret += gap;
            else ret += duration;
        }
        ret += duration;
        return ret;
    }
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ret = 0;
        for (int i = 1; i < timeSeries.length; i++) { // 一个变量照顾完前一个往后
            int x = timeSeries[i] - timeSeries[i - 1];
            if(x >= duration) ret += duration;
            else ret += x;
        }
        return ret + duration;
    }
}
